package c.x.jy.dao.dao;

import c.x.jy.dao.entity.BusinessConfigDefaultEntity;
import c.x.jy.dao.entity.BusinessConfigEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 商家配置表
 * 
 * @author amwhyh
 * @email xxx@xx.com
 * @date 2021-05-20 20:41:25
 */
@Mapper
public interface BusinessConfigDao extends BaseMapper<BusinessConfigEntity> {
	@Select("SELECT    *   FROM t_business_config_default")
	List<BusinessConfigDefaultEntity> queryDelultList();

	@Select("<script> SELECT 	bcd.*, bc.config_value FROM t_business_config_default bcd LEFT JOIN ( SELECT * FROM t_business_config <if test='businessId != null and businessId>0 '>   WHERE   business_id =${businessId}</if>  ) bc ON bcd. config_key = bc. config_key where type=1  </script>")
    List<BusinessConfigDefaultEntity> queryList(Long businessId);

	@Select("select * FROM t_business_config where business_id=#{businessId} and `config_key`= #{key} limit 1")
	BusinessConfigEntity selectByBusinessIdAndKey(Long businessId, String key);

	@Select("select * FROM  t_business_config_default  where   `config_key`=#{key} limit 1")
	BusinessConfigDefaultEntity selectDefultByBusinessIdAndKey(String key);

	@Update("<script>  INSERT INTO `t_business_config` (`business_id`, `config_key`, `config_value`) VALUES   <foreach collection='list' item='item' index='index'  separator=','> (  #{item.businessId},#{item.configKey},#{item.configValue}    )  </foreach> </script>")
	void insertbatths(List<BusinessConfigEntity> list);
}
